package com.hsp.reflection.question;

import com.hsp.Cat;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;
@SuppressWarnings({"all"})
public class ReflectionQuestion {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        //给据我们的配置文件里面的信息，创建对象，调用hi方法

        //1.职黑创建对象调用方法
        Cat cat = new Cat();
        //cat.hi();

        //2.文件流读取
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/com/hsp/re.properties"));
        String path=properties.getProperty("classpath").toString();
        String method=properties.get("method").toString();
        //System.out.println("这个的路径就是："+path);
        //System.out.println("这个的方法就是"+method);

        //类加载
        Class cls=Class.forName(path);
        //通过classa得到对象实例
        Object o = (Cat)cls.newInstance();
        System.out.println(o.getClass());//运行的类型Cat类型的

        Method method1=cls.getMethod(method);
        System.out.println("===================");
        method1.invoke(o);

    }
}
